package service.mock;

import org.springframework.stereotype.Service;
import service.CaptchaService;
import service.ServiceResponse;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by aceyin on 2015/6/8 0008.
 */
@Service
public class CaptchaServiceMock implements CaptchaService {
    private static final Map<String, String> CAPTCHA_CACHE = new HashMap<>();

    @Override
    public ServiceResponse sendSmsCaptcha(String mobile, String usage) {
        String captcha = mobile.substring(mobile.length() - 4);
        CAPTCHA_CACHE.put(mobile, captcha);
        return ServiceResponse.success().with("token", mobile).with("captcha", captcha);
    }

    @Override
    public ServiceResponse validate(String mobile, String usage, String token, String captcha) {
        return ServiceResponse.success().with("token", token).with("captcha", captcha);
    }
}
